
/*** Appendix Table 1 ***/
*Made by hand
/*** Appendix Figure A1 ***/

/** Appendix Table A3 -- Drop restriction that trades must occur more than 3 months after **/
/** For replication package, ignore this -- data will be identical to main sample **/
/*
global isbal="balanced"
global bond_age=0
do $codePath/prep_regression_data.do
*/
/**** TEMPORARY USE STATEMENT FOR REPLICATION PACKAGE *****/
use "$dataPath/final_regression_data.dta", clear
global  feet= 6
local feet $feet
capture drop pct_std
center percent_exposed_`feet', g(pct_std) standardize
replace pctexposed=percent_exposed_`feet'
label var pct_std "SLR Exposure"
label var log_median_hp "Log(Median House Price)"

forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_std*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"		
		}
	}



quietly{
est clear

eststo: reghdfe mma_spread_mvw_w pct_std pct_std_* if state != "CA", absorb(ym_date##fips) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "N"
estadd local has_issuer_fe "N"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w  pct_std_* if state != "CA", absorb(ym_date##fips dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "N"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w i.year  pct_std_*  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

}


esttab, compress nogaps b(3) keep(pct_std pct_std_* )   ///
 stats( has_controls  has_county_ym_fe has_issuer_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc   %9.0fc) ///
 labels( "Controls" "County-Year-Month FE" "District FE"  "Outcome Mean" "Outcome SD" "Observations")) /// 
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  
esttab using ${tablePath}/regressions_alltrades_appendix.tex, booktabs replace compress nogaps b(3) keep(pct_std pct_std_* )  ///
 stats(has_controls has_issuer_fe has_county_ym_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc    %9.0fc) ///
 labels("Controls" "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes


/*
global isbal="unbalanced"
global bond_age=1
quietly do $codePath/prep_regression_data.do
*/
/**** TEMPORARY USE STATEMENT FOR REPLICATION PACKAGE *****/
use "$dataPath/final_regression_data.dta", clear


/** Appendix Table A4 -- Relax Balanced Panel **/
/*** Filter back to age > 0.25**/
keep if bond_age_filter == 1

global  feet= 6
local feet $feet
capture drop pct_std*
center percent_exposed_`feet', g(pct_std) standardize
replace pctexposed=percent_exposed_`feet'
label var pct_std "SLR Exposure"
label var log_median_hp "Log(Median House Price)"

forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_std*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"
		}
	}


quietly{
est clear

eststo: reghdfe mma_spread_mvw_w pct_std pct_std_* if state != "CA", absorb(ym_date##fips) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "N"
estadd local has_issuer_fe "N"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w  pct_std_* if state != "CA", absorb(ym_date##fips dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "N"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w i.year  pct_std_*  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

}


esttab, compress nogaps b(3) keep(pct_std pct_std_* )   ///
 stats( has_controls  has_county_ym_fe has_issuer_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc   %9.0fc) ///
 labels( "Controls" "County-Year-Month FE" "District FE"  "Outcome Mean" "Outcome SD" "Observations")) /// 
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  
esttab using ${tablePath}/regressions_unbalanced_appendix.tex, booktabs replace compress nogaps b(3) keep(pct_std pct_std_* )  ///
 stats(has_controls  has_issuer_fe has_county_ym_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc    %9.0fc) ///
 labels("Controls" "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes



global isbal="balanced"
global bond_age=1
use "$dataPath/final_regression_data.dta", clear

/** Appendix Table A5 -- Robustness Specifications **/
global  feet= 6
local feet $feet
capture drop pct_std
replace pctexposed=percent_exposed_`feet'


label var log_median_hp "Log(Median House Price)"

est clear
local exp_type_percent_exposed_6 "6-foot, Frac."
local exp_type_percent_exposed_4 "4-foot, Frac."
local exp_type_pctval_exposed_6 "6-foot, Value"

capture drop pct_std
center percent_exposed_`feet', g(pct_std) standardize
center percent_exposed_`feet'_rslr50, g(pct_stdrslr50) standardize
center percent_exposed_`feet'_rslr80, g(pct_stdrslr80) standardize
center percent_exposed_`feet'_rslr100, g(pct_stdrslr100) standardize
replace pctexposed=percent_exposed_`feet'
label var pct_std "SLR Exposure"
label var log_median_hp "Log(Median House Price)"

label var pct_std "SLR Exposure"
forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_std*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"		
		}
	}

eststo: reghdfe mma_spread_mvw_w pct_std_*  $controls if state != "CA" [aweight = wgt], absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local has_controls "Y"
estadd local slr_type "`exp_type_`slr_var''"
estadd local equal_weight "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

foreach slr_var of varlist  percent_exposed_4 pctval_exposed_6 {
	capture drop pct_std
	center `slr_var', g(pct_std) standardize

	label var pct_std "SLR Exposure"


	
	forvalues i = 2001(1)2017 {
		if `i' != 2007 {
			capture drop pct_std_`i'
			gen pct_std_`i' = pct_std*(year == `i')
			label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"		
			}
		}

	eststo: reghdfe mma_spread_mvw_w pct_std_*  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
	estadd scalar N_true = e(N) + e(num_singletons)
	sum mma_spread_mvw_w if e(sample) == 1
	estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
	estadd local has_controls "Y"
	estadd local slr_type "`exp_type_`slr_var''"
estadd local equal_weight "N"	
	estadd local has_issuer_fe "Y"
	estadd local has_county_ym_fe "Y"

}
esttab, compress nogaps b(3) keep( pct_std_* )   ///
	  stats(has_controls  has_county_ym_fe has_issuer_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc   %9.0fc) ///
  labels( "Controls" "County-Year-Month FE" "District FE"  "Outcome Mean" "Outcome SD" "Observations")) /// 
  label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  
esttab using ${tablePath}/regressions_robustness_appendix.tex, booktabs replace compress nogaps b(3) keep( pct_std_* )  ///
  stats(slr_type equal_weight has_controls has_issuer_fe has_county_ym_fe  N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc    %9.0fc) ///
 labels("Exposure Measure" "State Equal-Weighted" "Controls" "District FE" "County-Year-Month FE" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes


/** Appendix Table A6 -- Spreads by maturity Different POST spec **/
global  feet= 6
local feet $feet
capture drop pct_std
local slr_var percent_exposed_6
center `slr_var', g(pct_std) standardize

label var log_median_hp "Log(Median House Price)"
gen pct_std_maturity = pct_std*log_maturity
est clear
foreach i in 2009 2010 2011 2012 2013 2014 {
	replace post = year > `i'
	label var log_maturity "Log(Maturity)"
	capture drop pct_std_post 
	gen pct_std_post = pct_std*post
	label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"
	capture drop pct_std_post_maturity
	gen pct_std_post_maturity = pct_std*log_maturity*post
	label var pct_std_post_maturity "SLR Exposure \$\times\$ 1(Post) \$\times\$ Log(Maturity)"
	quietly{
		eststo: reghdfe mma_spread_mvw_w  post#c.log_maturity  c.pct_std#c.log_maturity pct_std_post_maturity   $controls if  state != "CA", absorb(ym_date##dist_num $intcontrols) vce(cluster fips ym_date)
		estadd scalar N_true = e(N) + e(num_singletons)
		sum mma_spread_mvw_w if e(sample) == 1
		estadd scalar outcome_mean r(mean)
		estadd scalar outcome_sd r(sd)
		estadd local post_time "`i'"
		estadd local subsample "East \& Gulf"
		estadd local mat_range "All"
		estadd local has_controls "Y"
		estadd local has_issuer_fe "N"
		estadd local has_county_ym_fe "N"
		estadd local has_dist_ym_fe "Y"
		estadd local equal_weight "N"

		}
	}
esttab, compress nogaps b(3) keep( pct_std_post_maturity) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_gtrue, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles 
esttab using "$tablePath/regs_maturity_robustness_appendix.tex", booktabs replace compress nogaps b(3) keep(  pct_std_post_maturity) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes


est clear
foreach i in 2009 2010 2011 2012 2013 2014 {
	replace post = year > `i'
	label var log_maturity "Log(Maturity)"
	capture drop pct_std_post 
	gen pct_std_post = pct_std*post
	label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"
	quietly{
		eststo:  reghdfe mma_spread_mvw_w   pct_std_post $controls if longm==1 & state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
		estadd scalar N_true = e(N) + e(num_singletons)
		sum mma_spread_mvw_w if e(sample) == 1
		estadd scalar outcome_mean r(mean)
		estadd scalar outcome_sd r(sd)
		estadd local post_time "`i'"
		estadd local subsample "East \& Gulf"
		estadd local mat_range "> 10 years"
		estadd local has_controls "Y"
		estadd local has_county_ym_fe "Y"
		estadd local has_issuer_fe "Y"
		estadd local has_dist_ym_fe "N"
		estadd local equal_weight "N"
		}
	}
esttab, compress nogaps b(3) keep( pct_std_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles 
esttab using "$tablePath/regs_maturity_robustness_appendix_longm.tex", booktabs replace compress nogaps b(3) keep(  pct_std_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes



est clear
foreach i in 2009 2010 2011 2012 2013 2014 {
	replace post = year > `i'
	label var log_maturity "Log(Maturity)"
	capture drop pct_std_post 
	gen pct_std_post = pct_std*post
	label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"
	quietly{
		eststo:  reghdfe mma_spread_mvw_w   pct_std_post $controls if longm==0 & state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
		estadd scalar N_true = e(N) + e(num_singletons)
		sum mma_spread_mvw_w if e(sample) == 1
		estadd scalar outcome_mean r(mean)
		estadd scalar outcome_sd r(sd)
		estadd local post_time "`i'"
		estadd local subsample "East \& Gulf"
		estadd local mat_range "\$\leq\$ 10 years"
		estadd local has_controls "Y"
		estadd local has_county_ym_fe "Y"
		estadd local has_issuer_fe "Y"
		estadd local has_dist_ym_fe "N"
		estadd local equal_weight "N"
		}
	}
esttab, compress nogaps b(3) keep( pct_std_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles 
esttab using "$tablePath/regs_maturity_robustness_appendix_shortm.tex", booktabs replace compress nogaps b(3) keep(  pct_std_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes



/*** Appendix Table 7 ***/
/*** Storm Surge vs. SLR - Alternative Post ***/
global  feet= 6
local feet $feet
capture drop pct_std
local slr_var percent_exposed_6
center `slr_var', g(pct_std) standardize

label var log_median_hp "Log(Median House Price)"
est clear
foreach i in 2009 2010 2011 2012 2013 2014 {
	replace post = year > `i'
	capture drop pct_std_post 
	capture drop stormsurge_post
	
	gen stormsurge_post = stormsurge_std_w * post
	label var stormsurge_post "Storm Surge Exposure \$\times\$ 1(Post)"
	gen pct_std_post = pct_std*post
	label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"
	quietly{
eststo:  reghdfe mma_spread_mvw_w pct_std_post stormsurge_post   $controls if  state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
		estadd local post_time "`i'"
		estadd local subsample "East \& Gulf"
estadd local mat_range "All"
estadd local has_controls "Y"
estadd local has_county_ym_fe "Y"
estadd local has_issuer_fe "Y"
estadd local has_dist_ym_fe "N"
estadd local equal_weight "N"
		}
	}
esttab, compress nogaps b(3) keep( pct_std_post stormsurge_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles 
esttab using "$tablePath/regs_stormsurge_robustness_appendix.tex", booktabs replace compress nogaps b(3) keep(  pct_std_post stormsurge_post) ///
 stats( mat_range post_time has_controls has_issuer_fe has_county_ym_fe has_dist_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("Maturity Range" "Post = Year > x" "Controls" "District FE" "County-Year-Month FE" "District-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes


/*** Appendix Table A9 **/
/*** This is constructed in make_main_exhibits.do */
/* projections_robust.tex */

/*** Appendix Table A10 **/
/*** Effect of SLR on Yields, controlling for HP ***/

label var log_median_hp "log(Median House Price)"
label var log_med_pr_noexp_yr "log(MHP Not Exposed)"
label var log_med_pr_exp_yr "log(MHP Exposed)"
label var reg_price_index "Hedonic Price Index"
** Just using the old measure for a quantity restriction of 50 per period.
forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_std*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"		
		}
	}

quietly{ 
est clear
eststo: reghdfe mma_spread_mvw_w pct_std_2001-pct_std_2017 $controls if  state != "CA" &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
estadd local hp_measure "None"			
estadd local subsample "East \& Gulf"
estadd local worried "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
estadd local equal_weight "N"

	eststo: reghdfe mma_spread_mvw_w pct_std_2001-pct_std_2017 log_median_hp $controls if  state != "CA" &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
estadd local hp_measure "Median HP"			
estadd local subsample "East \& Gulf"
estadd local worried "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
estadd local equal_weight "N"

	eststo: reghdfe mma_spread_mvw_w pct_std_2001-pct_std_2017 c.log_med_pr_exp_yr c.log_med_pr_noexp_yr $controls if  state != "CA"  &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
estadd local hp_measure "Unexp. + Exposed HP"		
estadd local subsample "East \& Gulf"
estadd local worried "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
estadd local equal_weight "N"

eststo: reghdfe mma_spread_mvw_w pct_std_2001-pct_std_2017  c.log_zillow_hp $controls if  state != "CA" &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
estadd local hp_measure "Zillow HP"	
estadd local subsample "East \& Gulf"
estadd local worried "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
estadd local equal_weight "N"

	eststo: reghdfe mma_spread_mvw_w pct_std_2001-pct_std_2017  log_p10_price log_p25_price log_med_price log_p75_price log_p90_price  $controls if  state != "CA" &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
	estadd scalar outcome_sd r(sd)
estadd local hp_measure "Full Dist."
estadd local subsample "East \& Gulf"
estadd local worried "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
estadd local equal_weight "N"

}
esttab, compress nogaps b(3) keep( pct_std_*   ) ///
stats(   has_controls has_county_ym_fe has_county_ym_fe  outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels(  "Controls" "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
  label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles 
esttab using "$tablePath/regs_house_price_table_appendix_yearly.tex", booktabs replace compress nogaps b(3) keep(pct_std_*) ///
stats(  hp_measure has_controls has_county_ym_fe has_county_ym_fe  outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels("House Price" "Controls" "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
  label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes


/*** RANGE VS MEDIAN TABLE */
 
gen range_slr=year_range
gen med_slr=year_med
 
 label var range_treat "SLR Range Exposure"
 label var med_treat "SLR Median Exposure"
 label var range_slr  "SLR Range Projection"
 label var med_slr "SLR Median Projection"
  
quietly{ 
est clear
foreach i in 2009 2010 2011 2012 2013 2014 {
	replace post = year > `i'

eststo: reghdfe mma_spread_mvw_w range_treat med_treat  $controls if  state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local articles "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w  c.range_slr##c.pct_std c.med_slr##c.pct_std  $controls if  state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local articles "All"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"


replace range_treat=range_treat_r
replace med_treat=med_treat_r
replace range_slr=year_range_r
replace med_slr=year_med_r


eststo: reghdfe mma_spread_mvw_w range_treat med_treat  $controls if  state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local articles "Select"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

eststo: reghdfe mma_spread_mvw_w  c.range_slr##c.pct_std c.med_slr##c.pct_std  $controls if  state != "CA", absorb(ym_date##fips dist_num $intcontrols) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local articles "Select"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"
		}
	}

esttab, compress nogaps b(3) keep(range_treat med_treat  c.range_slr#c.pct_std c.med_slr#c.pct_std )  ///
 stats( articles has_controls  has_county_ym_fe has_issuer_fe outcome_mean outcome_sd N_true, fmt(  %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.0fc) ///
 labels( "Articles for Projection" "Controls" "County-Year-Month FE" "District FE"  "Outcome Mean" "Outcome SD" "Observations")) /// 
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  
esttab using ${tablePath}/projections_MG2.tex, booktabs replace compress nogaps b(3) keep(range_treat med_treat c.range_slr#c.pct_std c.med_slr#c.pct_std )  ///
 stats(articles has_controls  has_issuer_fe has_county_ym_fe outcome_mean outcome_sd N_true, fmt( %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc  %9.0fc) ///
 labels( "Articles for Projection" "Controls"  "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes
 


/*** Appendix Figure A3 ***/
/*** Year by year effect with full hp controls ***/
reghdfe mma_spread_mvw_w pct_std  ib2007.year#c.(pct_std ) ib2007.year#c.(log_median_hp) $controls if (eastcoast ==1 | gulfcoast ==1) & log_med_price != . , absorb(ym_date##fips $intcontrols dist_num) vce(cluster  fips ym_date)
mat b =e(b)
mat b = b[1,2..18]
mat b = b'
mat V =e(V)
mat V = vecdiag(V)
mat V = V[1,2..18]'
preserve
clear
svmat b
svmat V
keep if b1 != .
gen year = 2000 + _n
gen ci_upper = b1 + 1.96*sqrt(V1)
gen ci_lower = b1 - 1.96*sqrt(V1)
twoway (rcap ci_upper ci_lower year) (connected b1 year, mcolor(black) lcolor(black)), yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(off) 
graph export "$graphPath/regression_eastgulf_balanced_w_hp_controls.png", replace
graph export "$graphPath/regression_eastgulf_balanced_w_hp_controls.pdf", replace
restore



reghdfe mma_spread_mvw_w pct_std  ib2007.year#c.(pct_std ) ib2007.year#c.(log_median_hp  log_p10_price log_p25_price log_p75_price log_p90_price) $controls if (eastcoast ==1 | gulfcoast ==1) & log_med_price != . , absorb(ym_date##fips $intcontrols dist_num) vce(cluster  fips ym_date)
mat b =e(b)
mat b = b[1,2..18]
mat b = b'
mat V =e(V)
mat V = vecdiag(V)
mat V = V[1,2..18]'
preserve
clear
svmat b
svmat V
keep if b1 != .
gen year = 2000 + _n
gen ci_upper = b1 + 1.96*sqrt(V1)
gen ci_lower = b1 - 1.96*sqrt(V1)
gen model = "HP Dist"
tempfile tmp5
save `tmp5'
use `tmp1', clear
forvalues i = 2/5 {
	append using `tmp`i''
}
	twoway (rcap ci_upper ci_lower year) (connected b1 year, mcolor(black) lcolor(black)), yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(off) by(model)

encode model, gen(model2)
drop model
reshape wide ci_upper ci_lower b1 V1, i(year) j(model2)


twoway (rcap ci_upper1 ci_lower1 year) (connected b11 year) ///
  (rcap ci_upper2 ci_lower2 year) (connected b12 year) ///
  (rcap ci_upper3 ci_lower3 year) (connected b13 year) ///
  (rcap ci_upper4 ci_lower4 year) (connected b14 year) ///
  (rcap ci_upper5 ci_lower5 year) (connected b15 year) ///
, yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(label(1 "HP Dist") label(2 "Log(Median HP)") label(3 "Log(Median HP) by Exposure") label(4 "Log(Zillow HP)") label(5 "No controls") order( 5 2 3 4 1 ) )

twoway (connected b11 b12 b13 b14 b15 year) ///
, yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(label(1 "HP Dist") label(2 "Log(Median HP)") label(3 "Log(Median HP) by Exposure") label(4 "Log(Zillow HP)") label(5 "No controls") order( 5 2 3 4 1 ) )

graph export "$graphPath/regression_eastgulf_balanced_w_hp_controls_comparison.png", replace
graph export "$graphPath/regression_eastgulf_balanced_w_hp_controls_comparison.pdf", replace

restore





/*** Appendix Figure A2 ***/
/*** Year by year effect with RSLSR ***/
reghdfe mma_spread_mvw_w pct_stdrslr100  ib2007.year#c.(pct_stdrslr100 )  $controls if eastcoast ==1 | gulfcoast ==1 , absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
mat b =e(b)
mat b = b[1,2..18]
mat b = b'
mat V =e(V)
mat V = vecdiag(V)
mat V = V[1,2..18]'
preserve
clear
svmat b
svmat V
keep if b1 != .
gen year = 2000 + _n
gen ci_upper = b1 + 1.96*sqrt(V1)
gen ci_lower = b1 - 1.96*sqrt(V1)
twoway (rcap ci_upper ci_lower year) (connected b1 year, mcolor(black) lcolor(black)), yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(off) 
graph export "$graphPath/regression_eastgulf_balanced_w_rslr.png", replace
graph export "$graphPath/regression_eastgulf_balanced_w_rslr.pdf", replace
restore

/*** Appendix FIgure A4 (Effect of SLR on different HP measures **/
foreach y of varlist log_p10_price log_p25_price log_med_price log_p75_price log_p90_price log_zillow_hp log_med_pr_exp_yr log_med_pr_noexp_yr {
	eststo: reghdfe `y' pct_std ib2007.year#c.pct_std  $controls if  state != "CA" &log_median_hp !=., absorb(ym_date##fips dist_num  $intcontrols) vce(cluster fips ym_date)
	mat b =e(b)
	mat b = b[1,2..18]
	mat b = b'
	mat V =e(V)
	mat V = vecdiag(V)
	mat V = V[1,2..18]'
	preserve
	clear
	svmat b
	svmat V
	keep if b1 != .
	gen year = 2000 + _n
	gen ci_upper = b1 + 1.96*sqrt(V1)
	gen ci_lower = b1 - 1.96*sqrt(V1)
	twoway (rcap ci_upper ci_lower year) (connected b1 year, mcolor(black) lcolor(black)), yline(0, lcolor(black))  xlabel(2002(3)2017) xtitle("") legend(off) 
	graph export "$graphPath/hp_graph_appendix`y'.png", replace
	graph export "$graphPath/hp_graph_appendix`y'.pdf", replace
	restore
	}



/*** Appendix Table A2 -- RSLR vs. SLR Exposure ***/
/*** Year by year effect with RSLSR ***/
replace post = year >= 2013
replace pct_std_post = pct_std*post
label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"

estimates clear 
eststo: reghdfe mma_spread_mvw_w i.year  pct_std_post  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local slr_measure "SLR"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

replace pct_std_post = pct_stdrslr100*post
label var pct_std_post "SLR Exposure \$\times\$ 1(Post)"

eststo: reghdfe mma_spread_mvw_w i.year  pct_std_post  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local slr_measure "RSLR"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

corr pct_std pct_stdrslr100 if e(sample) 
forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_std*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"
		}
	}

eststo: reghdfe mma_spread_mvw_w i.year  pct_std_2001-pct_std_2017  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local slr_measure "SLR"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

forvalues i = 2001(1)2017 {
	if `i' != 2007 {
		capture drop pct_std_`i'
		gen pct_std_`i' = pct_stdrslr100*(year == `i')
		label var pct_std_`i' "SLR Exposure \$\times\$ 1(Year `i')"
		}
	}
eststo: reghdfe mma_spread_mvw_w i.year  pct_std_2001-pct_std_2017  $controls if state != "CA", absorb(ym_date##fips $intcontrols dist_num) vce(cluster fips ym_date)
estadd scalar N_true = e(N) + e(num_singletons)
sum mma_spread_mvw_w if e(sample) == 1
estadd scalar outcome_mean r(mean)
estadd scalar outcome_sd r(sd)
estadd local slr_measure "RSLR"
estadd local has_controls "Y"
estadd local has_issuer_fe "Y"
estadd local has_county_ym_fe "Y"

esttab, compress nogaps b(3) keep( pct_std_* )   ///
 stats( has_controls  has_county_ym_fe has_issuer_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc   %9.0fc) ///
 labels( "Controls" "County-Year-Month FE" "District FE"  "Outcome Mean" "Outcome SD" "Observations")) /// 
 label interaction(" X ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  
esttab using ${tablePath}/regressions_rslsr_appendix.tex, booktabs replace compress nogaps b(3) keep(pct_std_* )  ///
 stats(slr_measure has_controls  has_issuer_fe has_county_ym_fe outcome_mean outcome_sd N_true, fmt(%9.3fc %9.3fc %9.3fc %9.3fc %9.3fc %9.3fc    %9.0fc) ///
 labels("SLR Measure" "Controls" "District FE" "County-Year-Month FE" "Outcome Mean" "Outcome SD" "Observations")) ///
 label interaction(" $\times$ ") starlevels(* 0.10 ** 0.05 *** 0.01) nomtitles  nonotes

